package swarm // Package swarm import "xemo.top/docker/docker/api/types/swarm"

// Node represents a node
type Node struct {
	ID string
	Meta
	// Spec 定义用户指定的节点的所需状态。系统将尊重这一点，并且永远不会修改它。
	// Spec defines the desired state of the node as specified by the user.The system will honor this and will *never* modify it.
	Spec NodeSpec `json:",omitempty"`
	// Description 封装代理报告的节点属性。
	// Description encapsulates the properties of the Node as reported by the agent.
	Description NodeDescription `json:",omitempty"`
	// Status 提供管理器所看到的节点的当前状态。
	// Status provides the current status of the node,as seen by the manager.
	Status NodeStatus `json:",omitempty"`
	// ManagerStatus 如果节点是管理器，则提供节点的管理器组件的当前状态。
	// ManagerStatus provides the current status of the node's manager component,if the node is a manager.
	ManagerStatus *ManagerStatus `json:",omitempty"`
}

// NodeStatus 表示节点的状态
// NodeStatus represents the status of a node
type NodeStatus struct {
	State   NodeState `json:",omitempty"`
	Message string    `json:",omitempty"`
	Addr    string    `json:",omitempty"`
}

// NodeState 表示节点的状态
// NodeState represents the state of a node
type NodeState string

// NodeDescription 表示节点的说明。
// NodeDescription represents the description of a node.
type NodeDescription struct {
	Hostname  string            `json:",omitempty"`
	Platform  Platform          `json:",omitempty"`
	Resources Resources         `json:",omitempty"`
	Engine    EngineDescription `json:",omitempty"`
}

// EngineDescription 表示引擎的说明。
// EngineDescription represents the description of an engine.
type EngineDescription struct {
	EngineVersion string              `json:",omitempty"`
	Labels        map[string]string   `json:",omitempty"`
	Plugins       []PluginDescription `json:",omitempty"`
}

// PluginDescription 表示引擎插件的说明。
// PluginDescription represents the description of an engine plugin.
type PluginDescription struct {
	Type string `json:",omitempty"`
	Name string `json:",omitempty"`
}

// Platform represents the platform(Arch/os)
type Platform struct {
	Architecture string `json:",omitempty"`
	OS           string `json:",omitempty"`
}

// NodeSpec 表示节点的规格。
// NodeSpec represents the spec of a node.
type NodeSpec struct {
	Annotations
	Role         NodeRole         `json:",omitempty"`
	Availability NodeAvailability `json:",omitempty"`
}

// NodeAvailability 表示节点的可用性。
// NodeAvailability represents the availability of a node.
type NodeAvailability string

// NodeRole 表示节点的角色。
// NodeRole represents the role of a node.
type NodeRole string

// ManagerStatus 表示经理的状态
// ManagerStatus represents the status of a manager
type ManagerStatus struct {
	Leader       bool         `json:",omitempty"`
	Reachability Reachability `json:",omitempty"`
	Addr         string       `json:",omitempty"`
}

// Reachability 表示节点的可达性。
// Reachability represents the reachability of a node.
type Reachability string

const (
	// ReachabilityUnknown UNKNOWN
	ReachabilityUnknown Reachability = "unknown"
	// ReachabilityUnreachable UNREACHABLE
	ReachabilityUnreachable Reachability = "unreachable"
	// ReachabilityReachable REACHABLE
	ReachabilityReachable Reachability = "reachable"
)
